package com.sectop.bank.reports;

import com.sectop.bank.Account;
import com.sectop.bank.Bank;
import com.sectop.bank.Customer;
import com.sectop.bank.SavingAccount;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CustomerReport {

    public static void generateReport(Bank bank) {
//        Bank bank = Bank.getInstance();
        Customer customer;
        ArrayList<Customer> list = (ArrayList<Customer>)bank.getCustomers();





        System.out.println("\t\t\tCUSTOMERS REPORT");
        System.out.println("\t\t\t================");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            customer = (Customer) iterator.next();
            System.out.println();
            System.out.println("Customer: "
                    + customer.getLastName() + ", "
                    + customer.getFirstName());

            for ( int acct_idx = 0; acct_idx < customer.getNumOfAccounts(); acct_idx++ ) {
                Account account = customer.getAccount(acct_idx);
                String  account_type = "";
                if(account instanceof SavingAccount){
                    account_type = "SavingAccount";
                }else {
                    account_type = "CheckingAccount";
                }
                System.out.print(account_type+": current balance is ￥");
                System.out.println(account.getBalance());


                // Determine the account type
                /*** Step 1:
                 **** Use the instanceof operator to test what type of account
                 **** we have and set account_type to an appropriate value, such
                 **** as "Savings Account" or "Checking Account".
                 ***/

                // Print the current balance of the account
                /*** Step 2:
                 **** Print out the type of account and the balance.
                 **** Feel free to use the currency_format formatter
                 **** to generate a "currency string" for the balance.
                 ***/
            }
            System.out.println("\n");
        }

        }


//        for ( int cust_idx = 0; cust_idx < bank.getNumOfCustomers(); cust_idx++ ) {
//            customer = bank.getCustomer(cust_idx);
//
//            System.out.println();
//            System.out.println("Customer: "
//                    + customer.getLastName() + ", "
//                    + customer.getFirstName());
//
//            for ( int acct_idx = 0; acct_idx < customer.getNumOfAccounts(); acct_idx++ ) {
//                Account account = customer.getAccount(acct_idx);
//                String  account_type = "";
//                if(account instanceof SavingAccount){
//                    account_type = "SavingAccount";
//                }else {
//                    account_type = "CheckingAccount";
//                }
//                System.out.print(account_type+": current balance is ￥");
//                System.out.println(account.getBalance());
//
//
//                // Determine the account type
//                /*** Step 1:
//                 **** Use the instanceof operator to test what type of account
//                 **** we have and set account_type to an appropriate value, such
//                 **** as "Savings Account" or "Checking Account".
//                 ***/
//
//                // Print the current balance of the account
//                /*** Step 2:
//                 **** Print out the type of account and the balance.
//                 **** Feel free to use the currency_format formatter
//                 **** to generate a "currency string" for the balance.
//                 ***/
//            }
//            System.out.println("\n");
//        }
    }

